import { activeMenusLists } from '@/http/login'
import { menus } from "@/router/routes.js";
import { rulesMenus } from '@/utils/common'
import { baseRouter } from '@/router/index.js';
import { cloneDeep } from 'lodash';
export default {
    namespaced: true,
    state: {
        // 定义动态路由容器  =-- 存储动态路由
        activemenus: []
    },
    mutations: {
        // 设置菜单导航
        setMenusList(state, payload) {
            state.activemenus = payload
        },
        // 清空菜单导航
        removeMenusList(state) {
            state.activemenus = []
        }
    },
    actions: {
        async getMenusList({ commit, rootState }) {
            console.log(rootState, 'vuex我看看这个是个啥玩意儿');
            let res = await activeMenusLists({
                token: rootState.login.logininfo.role
            })
            console.log('后端返回的动态路由的数据wsb', res);
            let myMenu = rulesMenus(menus, res.data.data)
            // console.log("这是最后处理好的动态路由第一步----", menus, res.data.data, myMenu);

            //存储动态菜单导航-----------------
            commit('setMenusList', myMenu);

            let mybaseRouters = cloneDeep(baseRouter)

            mybaseRouters[0].children.push(...myMenu)

            console.log('这里是原本路由加上动态路由', mybaseRouters);

            return mybaseRouters



        }

    }
}